from keras.models import load_model
import cv2
import numpy as np


# path = "img_cut/2/1700784795.749269.jpg"
# imgsize = [135, 50]
# img = cv2.imread(path, cv2.IMREAD_COLOR)  # 读入图片
# img = cv2.resize(img, (imgsize[0], imgsize[1]))  # 设定图片像素维度
# cv2.imshow('r',img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

# 加载保存的模型
loaded_model = load_model('model.h5')

# path = "img_cut/1/1700784790.708128.jpg"#R B
# path = "img_cut/2/1700784794.5067003.jpg"#R 2
# path = "img_cut/2/1700784789.953749.jpg"#z 2
# path = "img_cut/2/1700784794.4329827.jpg"#R 2
# path = "img_cut/2/1700784794.5959187.jpg"#R z
# path = "img_cut/2/1700784795.749269.jpg"#R 2
# path = "img_cut/2/1700784789.953749.jpg"#R 2
# path = "img_cut/3/1700784790.53992.jpg"#R 3
# path = "img_cut/3/1700784789.8461092.jpg"#R 3
# path = "img_cut/A/1700784790.7041285.jpg"  #A
# path = "img_cut/8/1700785217.276496.jpg" # B
# path = "img_cut/8/1700785217.877106.jpg" # 8
# path = "img_cut/8/1700785217.3786812.jpg" #8
# path = "img_cut/b/1700785201.4458528.jpg" #B
# path = "img_cut/D/1700784791.8170073.jpg" #D
path = "img_cut/I/1700785524.9712782.jpg" #L
# path = "img_cut/7/1700617376.940508.jpg"

imgsize = [105, 96]
img = cv2.imread(path, cv2.IMREAD_COLOR)  # 读入图片
img = cv2.resize(img, (imgsize[0], imgsize[1]))  # 设定图片像素维度
# cv2.imshow('r',img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

image_array = np.array(img)  # 将图像转换为数组
image_array = image_array / 255.0  # 对图像进行归一化处理，将像素值缩放到[0, 1]范围

# 将图像数据传递给模型进行预测
predictions = loaded_model.predict(np.expand_dims(image_array, axis=0))  # 将图像数组转换为模型所需的输入格式并进行预测
print(predictions[0])
max_value = np.max(predictions[0])
print("最大值：", max_value)
predicted_class_index = np.argmax(predictions)
# list = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
list = ["2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"]
print(predicted_class_index)
print(list[predicted_class_index])
# 使用加载的模型进行预测或其他操作
# predictions = loaded_model.predict(data)
